package com.xiong.wuliao.util;

import com.xiong.wuliao.entity.ZhuanLan;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 分类页专栏部分的服务器数据解析
 * Created by Administrator on 2016/11/7.
 */
public class ZhuanLanJSON {

    public static List<ZhuanLan> saveZhuanLanData(String s) {
        List<ZhuanLan> zhuanLanList = new ArrayList<>();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(s.trim());
            JSONObject object = jsonObject.optJSONObject("data");
            JSONArray jsonArray = object.optJSONArray("channel_groups");
            JSONObject object1 = jsonArray.optJSONObject(0);
            JSONArray array = object1.optJSONArray("channels");
            for (int index = 0; index < array.length(); index++) {
                ZhuanLan zhuanLan = new ZhuanLan();
                JSONObject obj = array.optJSONObject(index);

                zhuanLan.setGroup_id(obj.optString("group_id"));
                zhuanLan.setIcon_url(obj.optString("icon_url"));
                zhuanLan.setId(obj.optString("id"));
                zhuanLan.setItems_count(obj.optString("items_count"));
                zhuanLan.setName(obj.optString("name"));
                zhuanLan.setOrder(obj.optString("order"));
                zhuanLan.setStatus(obj.optString("status"));

                zhuanLanList.add(zhuanLan);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return zhuanLanList;
    }
}
